using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using CloudBookList.Configuration;
using CloudBookList.Web;

namespace CloudBookList.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class CloudBookListDbContextFactory : IDesignTimeDbContextFactory<CloudBookListDbContext>
    {
        public CloudBookListDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<CloudBookListDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            CloudBookListDbContextConfigurer.Configure(builder, configuration.GetConnectionString(CloudBookListConsts.ConnectionStringName));

            return new CloudBookListDbContext(builder.Options);
        }
    }
}
